package com.zhong.gang.app.ui.login;

import android.text.TextUtils;
import android.view.View;
import androidx.annotation.NonNull;
import com.luck.picture.lib.tools.ToastUtils;
import com.zhong.gang.app.R;
import com.zhong.gang.app.databinding.ActivityForgetPassBinding;
import com.zhong.gang.applib.base.act.ActBase;
import com.zhong.gang.applib.utils.CheckedUtils;

public class ForgetPassAct extends ActBase<ActivityForgetPassBinding> {
    private LoginPresenter presenter;

    @Override
    public int LayoutRes() {
        return R.layout.activity_forget_pass;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "忘记密码";
    }

    @Override
    public void initView() {
        bind.setAct(this);
        presenter = new LoginPresenter();
    }

    public void onViewClicked(View view) {
        String account = bind.account.getText().toString();
        String phone = bind.phone.getText().toString();
        String pass = bind.pass.getText().toString();
        String rePass = bind.rePass.getText().toString();
        String code = bind.code.getText().toString();
        switch (view.getId()){
            case R.id.send_code:
                if (!CheckedUtils.isPhone(phone)){
                    ToastUtils.s(this,"手机号输入不正确");
                    return;
                }
                presenter.sendCode(this,phone,bind.sendCode);
                break;
            case R.id.sure:
                if (TextUtils.isEmpty(account)){
                    ToastUtils.s(this,"请输入账号");
                    return;
                }
                if (!CheckedUtils.isPhone(phone)){
                    ToastUtils.s(this,"手机号输入不正确");
                    return;
                }
                if (TextUtils.isEmpty(pass)){
                    ToastUtils.s(this,"请输入新密码");
                    return;
                }
                if (!CheckedUtils.isSome(pass,rePass)){
                    ToastUtils.s(this,"两次密码输入不相同");
                    return;
                }
                if (TextUtils.isEmpty(code)){
                    ToastUtils.s(this,"请输入验证码");
                    return;
                }
                presenter.forgetPass(this,account,phone,code,pass);
                break;
        }
    }
}
